package com.gz.purchase.widget;


import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.gz.purchase.R;
import com.gz.purchase.adapter.SpinnerAdapter;


public class SpinerPopWindow extends PopupWindow implements OnItemClickListener{

	private Context mContext;
	private ListView mListView;
	private ISpinnerOnItemSelectListener mItemSelectListener;
	

		public SpinerPopWindow(Context context) {
		super(context);
		mContext = context;
		init();
	}

	private void init() {
		View view = LayoutInflater.from(mContext).inflate(R.layout.spiner_window_layout, null);
		setContentView(view);
		setWidth(LayoutParams.WRAP_CONTENT);
		setHeight(LayoutParams.WRAP_CONTENT);
		setFocusable(true);
		ColorDrawable dw = new ColorDrawable(0x00);
		setBackgroundDrawable(dw);

		mListView = (ListView) view.findViewById(R.id.listview);
		mListView.setOnItemClickListener(this);
	}
	
	
	public void setItemListener(ISpinnerOnItemSelectListener listener){
		mItemSelectListener = listener;
	}

	public void setAdatper(SpinnerAdapter adapter){
		mListView.setAdapter(adapter);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View view, int pos, long arg3) {
		dismiss();
		if (mItemSelectListener != null){
			mItemSelectListener.onSpinnerItemClick(pos);
		}
	}

    public  interface ISpinnerOnItemSelectListener{
		 void onSpinnerItemClick(int position);
	}
	
}
